package com.yxjx.duoxue.course.datamodel;

import java.io.IOException;
import java.util.List;

import org.codehaus.jackson.type.TypeReference;
import org.json.JSONObject;

import com.yxjx.duoxue.datamodel.DMObject;
import com.yxjx.duoxue.utils.JsonUtils;

/**
 * 广告详情
 * 
 * @author zhangxs
 * @date 2015年4月17日
 * 
 */
public class AdDTS extends DMObject implements java.io.Serializable {

	private static final long serialVersionUID = 1L;

	// 广告编号
	private Integer id = -1;
	// 广告类型,1课程列表页广告,2课详页广告
	private Integer adType = 1;
	// 广告标题
	private String adTitle = "";
	// 广告描述
	private String adDes = "";
	// 图片地址
	private String adImage = "";
	// 链接url
	private String adUrl;
	// 是否分享,0不分享,1分享
	private Integer isShare = 1;

	/** ############ 以下预留部分 ############# **/
	// (预留)价格显示状态,0都不显示,1显示价格,2显示折扣
	private Integer priceShowStatus = 0;
	// (预留)原价
	private Integer costPrice = 0;
	// (预留)折扣价
	private Integer discountPrice = 0;
	// (预留)打折信息
	private String discount = "";
	// (预留)位置信息,1号位,2号位...
	private Integer positionId = 0;
	// (预留)省份id
	private Integer provinceId;
	// (预留)城市id
	private Integer cityId;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getAdType() {
		return adType;
	}

	public void setAdType(Integer adType) {
		this.adType = adType;
	}

	public String getAdTitle() {
		return adTitle;
	}

	public void setAdTitle(String adTitle) {
		this.adTitle = adTitle;
	}

	public String getAdDes() {
		return adDes;
	}

	public void setAdDes(String adDes) {
		this.adDes = adDes;
	}

	public String getAdImage() {
		return adImage;
	}

	public void setAdImage(String adImage) {
		this.adImage = adImage;
	}

	public String getAdUrl() {
		return adUrl;
	}

	public void setAdUrl(String adUrl) {
		this.adUrl = adUrl;
	}

	public Integer getPriceShowStatus() {
		return priceShowStatus;
	}

	public void setPriceShowStatus(Integer priceShowStatus) {
		this.priceShowStatus = priceShowStatus;
	}

	public Integer getCostPrice() {
		return costPrice;
	}

	public void setCostPrice(Integer costPrice) {
		this.costPrice = costPrice;
	}

	public Integer getDiscountPrice() {
		return discountPrice;
	}

	public void setDiscountPrice(Integer discountPrice) {
		this.discountPrice = discountPrice;
	}

	public String getDiscount() {
		return discount;
	}

	public void setDiscount(String discount) {
		this.discount = discount;
	}

	public Integer getIsShare() {
		return isShare;
	}

	public void setIsShare(Integer isShare) {
		this.isShare = isShare;
	}

	public Integer getPositionId() {
		return positionId;
	}

	public void setPositionId(Integer positionId) {
		this.positionId = positionId;
	}

	public Integer getProvinceId() {
		return provinceId;
	}

	public void setProvinceId(Integer provinceId) {
		this.provinceId = provinceId;
	}

	public Integer getCityId() {
		return cityId;
	}

	public void setCityId(Integer cityId) {
		this.cityId = cityId;
	}

	@Override
	public String toString() {
		return "{\"id\":\"" + id + "\", \"adType\":\"" + adType
				+ "\", \"adTitle\":\"" + adTitle + "\", \"adDes\":\"" + adDes
				+ "\", \"adImage\":\"" + adImage + "\", \"adUrl\":\"" + adUrl
				+ "\", \"priceShowStatus\":\"" + priceShowStatus
				+ "\", \"costPrice\":\"" + costPrice
				+ "\", \"discountPrice\":\"" + discountPrice
				+ "\", \"discount\":\"" + discount + "\", \"isShare\":\""
				+ isShare + "\", \"positionId\":\"" + positionId
				+ "\", \"provinceId\":\"" + provinceId + "\", \"cityId\":\""
				+ cityId + "\"}";
	}

	public static AdDTS from(JSONObject jo) {
		if (jo == null) {
			return null;
		}
		AdDTS ret = new AdDTS();
		ret.setAdDes(getString(jo, "adDes"));
		ret.setAdImage(getString(jo, "adImage"));
		ret.setAdTitle(getString(jo, "adTitle"));
		ret.setAdType(getInteger(jo, "adType"));
		ret.setAdUrl(getString(jo, "adUrl"));
		ret.setCityId(getInteger(jo, "cityId"));
		ret.setId(getInteger(jo, "id"));
		ret.setIsShare(getInteger(jo, "isShare"));
		ret.setPositionId(getInteger(jo, "positionId"));
		ret.setProvinceId(getInteger(jo, "provinceId"));
		return ret;
	}

	public static List<AdDTS> arrayFrom(String jsonStr) {
		try {
			return JsonUtils.toJavaBeanList(jsonStr,
					new TypeReference<List<AdDTS>>() {
					});
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static AdDTS fromAdListDTS(AdListDTS listDTS) {
		if (listDTS == null) {
			return null;
		}

		AdDTS ret = new AdDTS();
		ret.setId(listDTS.getId());
		ret.setAdType(listDTS.getAdType());
		ret.setAdTitle(listDTS.getAdTitle());
		ret.setAdDes(listDTS.getAdDes());
		ret.setAdImage(listDTS.getAdImage());
		ret.setAdUrl(listDTS.getAdUrl());
		ret.setIsShare(listDTS.getIsShare());
		return ret;

	}
}
